var a = 0;
var ion = "#fUI/UIWindow2.img/QuestAlarm/BtQ/normal/0#"
var text;
var selects; //记录玩家的选项
var buynum = 0;
var itemlist = Array(
Array(1004282,30000),
Array(1004281,30000),
Array(1004294,30000),
Array(1004323,30000),
Array(1012508,30000),  
Array(1004325,30000),
Array(1004326,30000), 
Array(1004385,30000), 
Array(1004387,30000),
Array(1004405,30000), 
Array(1004403,30000),
Array(1004408,30000),
Array(1004409,30000),
Array(1004411,30000), 
Array(1004413,30000), 
Array(1004414,30000), 
Array(1004448,30000),
Array(1004458,35000),
Array(1004459,35000), 
Array(1004460,35000),
Array(1004463,35000),
Array(1004467,35000),
Array(1004468,35000),
Array(1004469,35000),
Array(1004470,35000),
Array(1004481,35000),
Array(1004478,35000),
Array(1004473,35000),
Array(1004472,35000),
Array(1004471,35000),
Array(1004486,35000),
Array(1004487,35000),
Array(1004501,35000),
Array(1004505,35000),
Array(1004506,35000),
Array(1004508,35000),
Array(1004490,35000),
Array(1004489,35000),
Array(1004562,35000),
Array(1004564,35000),
Array(1004565,35000),
Array(1004566,35000),
Array(1004581,35000),
Array(1004603,35000),
Array(1004602,35000),
Array(1004609,35000),
Array(1004610,35000),
Array(1004614,35000),
Array(1004613,35000),
Array(1004612,35000),
Array(1004615,35000),
Array(1004619,35000),
Array(1004620,35000),
Array(1004635,30000),
Array(1004634,30000),
Array(1004633,30000),
Array(1004659,30000),
Array(1004397,30000),
Array(1004642,30000),
Array(1004641,30000),
Array(1004640,30000),
Array(1004790,50000),
Array(1004788,50000),
Array(1004787,50000),
Array(1004760,50000),
Array(1004758,30000),
Array(1004759,30000),
Array(1004757,50000),
Array(1004756,50000),
Array(1004739,30000),
Array(1004712,30000),
Array(1004710,30000),
Array(1004709,30000),
Array(1004708,30000),
Array(1004706,30000),
Array(1004690,30000),
Array(1004695,30000),
Array(1004696,30000),
Array(1004488,30000),
Array(1003362,30000),
Array(1004639,30000),
Array(1004655,30000),
Array(1004656,30000),
Array(1004657,30000),
Array(1004658,30000),
Array(1004665,30000),
Array(1004668,30000),
Array(1004628,30000),
Array(1004629,30000),
Array(1004630,30000),
Array(1004631,30000),
Array(1004632,30000),
Array(1004636,30000),
Array(1004638,30000),
Array(1004544,30000),
Array(1004545,30000),
Array(1004546,30000),
Array(1004547,30000),
Array(1004548,30000),
Array(1004513,30000),
Array(1004510,30000),
Array(1004511,30000),
Array(1004512,30000),
Array(1000084,30000),
Array(1001105,30000),
Array(1004542,30000),
Array(1004543,30000),
Array(1003349,30000),
Array(1001106,30000),
Array(4021002,30000),
Array(1004428,30000),
Array(1004568,30000),
Array(1002665,30000),
Array(1004163,30000),
Array(1004600,30000),
Array(1004590,30000),
Array(1004589,30000),
Array(1004583,30000),
Array(1004580,30000),
Array(1004569,30000),
Array(1004541,30000),
Array(1004279,30000),
Array(1004336,30000),
Array(1004337,30000),
Array(1001094,30000),
Array(1003636,30000),
Array(1002598,30000),
Array(1004169,30000),
Array(1000070,30000),
Array(1001093,30000),
Array(1003436,30000),
Array(1004167,30000),
Array(1004282,30000),
Array(1003952,30000),
Array(1003131,30000),
Array(1004094,30000),
Array(1004112,30000),
Array(1004211,30000),
Array(1004193,30000),
Array(1003859,30000),
Array(1004137,30000),
Array(1003831,30000),
Array(1003955,30000),
Array(1004095,30000),
Array(1004029,30000),
Array(1003901,30000),
Array(1004110,30000),
Array(1001083,30000),
Array(1001095,30000),
Array(1004200,30000),
Array(1003892,30000),
Array(1004124,30000),
Array(1001097,30000),
Array(1000074,30000),
Array(1004200,30000),
Array(1004204,30000),
Array(1004205,30000),
Array(1003950,30000),
Array(1004126,30000),
Array(1003883,30000),
Array(1004158,30000),
Array(1004114,30000),
Array(1004025,30000),
Array(1004025,30000),
Array(1002845,30000),
Array(1002721,30000),
Array(1002894,30000),
Array(1002895,30000),
Array(1002896,30000),
Array(1002897,30000),
Array(1002898,30000),
Array(1002899,30000),
Array(1002900,30000),
Array(1002901,30000),
Array(1002902,30000),
Array(1002568,30000),
Array(1002888,30000),
Array(1002890,30000),
Array(1002863,30000),
Array(1003207,30000),
Array(1003051,30000),
Array(1003048,30000),
Array(1002995,30000),
Array(1002876,30000),
Array(1002839,30000),
Array(1001048,30000),
Array(1003214,30000),
Array(1003141,30000),
Array(1003269,30000),
Array(1003268,30000),
Array(1003848,30000),
Array(1003849,30000),
Array(1003850,30000),
Array(1003851,30000),
Array(1003852,30000),
Array(1003519,30000),
Array(1003520,30000),
Array(1002726,30000),
Array(1002524,30000),
Array(1002714,30000),
Array(1002841,30000),
Array(1003220,30000),
Array(1003170,30000),
Array(1003226,30000),
Array(1003902,30000),
Array(2432567,30000),
Array(1001075,30000),
Array(1003252,30000),
Array(1003249,30000),
Array(1001101,30000),
Array(1002998,30000),
Array(1003091,30000),
Array(1003114,30000),
Array(1003075,30000),
Array(1000043,30000),
Array(1003149,30000),
Array(1002988,30000),
Array(1003505,30000),
Array(1003504,30000),
Array(1003965,30000),
Array(1003964,30000),
Array(1003920,30000),
Array(1003921,30000),
Array(1003918,30000),
Array(1003861,30000),
Array(1003865,30000),
Array(1003919,30000),
Array(1002566,30000),
Array(1003581,30000),
Array(1003417,30000),
Array(1003271,30000),
Array(1003196,30000),
Array(1003193,30000),
Array(1003194,30000),
Array(1004026,30000),
Array(1004027,30000),
Array(1004028,30000),
Array(1004029,30000)
);

function start() {
    a = -1;
    action(1, 0, 0);
}

function action(mode, type, selection) {
    if (mode == -1) {
        cm.dispose();
    } else {
        if (mode == 1)
            a++;
        else
            a--;
        if (a == -1) {
            cm.dispose();
        } else if (a == 0) {
			text = ion+"#k亲爱的#r#h0#,#k您好请选择您希望购买的道具：\r\n\r\n#b";
			for (var i=1; i<=itemlist.length; i++) {
				text += "#L" + (i) + "##i" + itemlist[i-1] + ":##t" + itemlist[i-1] + "# - #r"+itemlist[i-1][1]+"#b点卷  \r\n";
				if (i != 0 && (i+1) % 5 == 0) {
					text += "\r\n";
				}
			}
            cm.sendSimple(text);
        } else if (a == 1) {
			selects = (selection-1);
            buynum = 1;
            cm.sendYesNo("你想购买" + buynum + "个#r#i" + itemlist[selects][0] + "##k？\r\n你将使用掉" + (buynum * itemlist[selects][1]) + "点卷。");
		} else if (a == 2) {
            if (cm.getChar().getCSPoints(1) >= buynum * itemlist[selects][1]) {
                cm.getChar().modifyCSPoints(1, -buynum * itemlist[selects][1]);
                cm.gainItem(itemlist[selects][0], buynum);
                cm.sendOk("购买成功了！");
                cm.dispose();
            } else {
                cm.sendOk("对不起，你没有足够的点卷。");
                cm.dispose();
			}
		}
	}
}